package com.itheima.fileIO;

import java.io.File;
import java.util.HashMap;

public class fileDemo04 {
    public static void main(String[] args) {
        File file=new File("FileIo");
        HashMap<String,Integer> hm=new HashMap<>();
        getCount(hm,file);
        System.out.println(hm);

    }

    private static void getCount(HashMap<String, Integer> hm, File file) {
        File[] files = file.listFiles();
        for (File f : files) {
            if (f.isFile()){
                String name = f.getName();
                String[] names = name.split("\\.");
                if (names.length==2) {
                    String getEndName = names[1];
                    if (hm.containsKey(getEndName)){
                        Integer count = hm.get(getEndName);
                        count++;
                        hm.put(getEndName,count);
                    }else{
                        hm.put(getEndName,1);
                    }
                }
            }else {
                getCount(hm,f);
            }
        }

    }
}
